package cn.nlte.frame.gui.tabclose;

import java.awt.Color;
import javax.swing.Icon;

/**
 * 本类用于封装带关闭按钮及图标的选项卡面板
 *
 * @author yetao
 */
public class JTabbedPanelTab extends javax.swing.JPanel {

    private String panelname = null;
    private String jtabbedpanename = null;

    /**
     *
     * @param panelname
     * @param jtabbedpanename
     * @param showText
     */
    public JTabbedPanelTab(String panelname, String jtabbedpanename, String showText) {
        initComponents();
        this.panelname = panelname;
        this.jtabbedpanename = jtabbedpanename;
        jLabel1.setText(showText);
        //this.setBackground(null);
    }

    /**
     *
     * @param panelname
     * @param jtabbedpanename
     * @param showText
     * @param ico
     */
    public JTabbedPanelTab(String panelname, String jtabbedpanename, String showText, String ico) {
        initComponents();
        this.panelname = panelname;
        this.jtabbedpanename = jtabbedpanename;
        jLabel1.setText(showText);
        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource(ico)));
    }

    /**
     *
     * @param panelname
     * @param jtabbedpanename
     * @param showText
     * @param ico
     */
    public JTabbedPanelTab(String panelname, String jtabbedpanename, String showText, Icon ico) {
        initComponents();
        this.panelname = panelname;
        this.jtabbedpanename = jtabbedpanename;
        jLabel1.setText(showText);
        jLabel2.setIcon(ico);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();

        setBackground(null);
        setForeground(new java.awt.Color(240, 240, 240));
        java.awt.GridBagLayout layout = new java.awt.GridBagLayout();
        layout.columnWidths = new int[] {0, 5, 0, 5, 0, 5, 0};
        layout.rowHeights = new int[] {0};
        setLayout(layout);

        jLabel1.setBackground(null);
        jLabel1.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("TabPanel的按键");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        add(jLabel1, gridBagConstraints);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cn/nlte/frame/gui/tabclose/stock_close.png"))); // NOI18N
        jButton1.setAlignmentX(0.5F);
        jButton1.setIconTextGap(1);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        add(jButton1, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        add(jLabel2, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        JTabbedPaneManager jtpm = JTabbedPaneManager.getInstance(jtabbedpanename);
        jtpm.removeTab(panelname);
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration//GEN-END:variables

    public void setLabelColor(Color color) {
        jLabel1.setForeground(color);
    }
}
